﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AIStudio.Wpf.Business.IBussiness;
using AIStudio.Wpf.Entity.Models.Models;
using Newtonsoft.Json;
using Prism.Ioc;
using Prism.Mvvm;

namespace AIStudio.Wpf.Base_Manage.ViewModels
{
    public class Base_AppSecretEditViewModel :BindableBase
    {
        private string _title;
        public string Title
        {
            get { return _title; }
            set
            {
                SetProperty(ref _title, value);
            }
        }

        private bool _disabled;
        public bool Disabled
        {
            get { return _disabled; }
            set
            {
                SetProperty(ref _disabled, value);
            }
        }

        private Base_AppSecret _data;
        public Base_AppSecret Data
        {
            //get { return _data; }
            //set
            //{
            //    SetProperty(ref _data, value);
            //}

            get { return _data; }
            set
            {
                if (value != _data)
                {
                    _data = value;
                    RaisePropertyChanged("Data");
                }
            }

        }

        protected string Area { get; set; }

        protected IDataProvider _dataProvider { get { return ContainerLocator.Current.Resolve<IDataProvider>(); } }

        public Base_AppSecretEditViewModel(Base_AppSecret data, string area, string title = "编辑表单")
        {
            Data = data;
            Title = title;
            Area = area;
        }

        protected void InitData()
        {
            Data = System.Activator.CreateInstance<Base_AppSecret>();
        }

        protected virtual async void GetData(Base_AppSecret para)
        {
            try
            {
                ShowWait();

                var result = await _dataProvider.GetData<Base_AppSecret>($"/{Area}/{typeof(Base_AppSecret).Name}/GetTheData", JsonConvert.SerializeObject(new { id = para.Id }));
                if (!result.Success)
                {
                    throw new Exception(result.Msg);
                }
                Data = result.Data;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                HideWait();
            }
        }

        protected void ShowWait()
        {
          
        }

        protected void HideWait()
        {
          
        }


        protected Base_AppSecretEditViewModel()
        {

        }

        ~Base_AppSecretEditViewModel()
        {
            this.Dispose(false);
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                //执行基本的清理代码
            }
        }
    }
}
